import 'package:flutter/material.dart';

class LogisticsTimeline extends StatelessWidget {
  final List<Map<String, dynamic>> timeline;

  const LogisticsTimeline({
    super.key,
    required this.timeline,
  });

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      padding: const EdgeInsets.all(16),
      itemCount: timeline.length,
      itemBuilder: (context, index) {
        final item = timeline[index];
        final isFirst = index == 0;
        final isLast = index == timeline.length - 1;

        return Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            // 时间轴
            SizedBox(
              width: 24,
              child: Column(
                children: [
                  // 上半部分连接线
                  if (!isFirst)
                    Container(
                      width: 2,
                      height: 20,
                      color: const Color(0xFFEEEEEE),
                    ),
                  // 节点
                  Container(
                    width: 12,
                    height: 12,
                    decoration: BoxDecoration(
                      color: isFirst
                          ? const Color(0xFFFF4141)
                          : const Color(0xFFEEEEEE),
                      shape: BoxShape.circle,
                      border: Border.all(
                        color: isFirst
                            ? const Color(0xFFFF4141)
                            : const Color(0xFFEEEEEE),
                        width: 2,
                      ),
                    ),
                  ),
                  // 下半部分连接线
                  if (!isLast)
                    Container(
                      width: 2,
                      height: 40,
                      color: const Color(0xFFEEEEEE),
                    ),
                ],
              ),
            ),
            const SizedBox(width: 12),
            // 内容
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    item['desc'],
                    style: TextStyle(
                      fontSize: 14,
                      color: isFirst
                          ? const Color(0xFF333333)
                          : const Color(0xFF999999),
                      height: 1.4,
                    ),
                  ),
                  const SizedBox(height: 4),
                  Text(
                    item['time'],
                    style: const TextStyle(
                      fontSize: 12,
                      color: Color(0xFF999999),
                    ),
                  ),
                  if (!isLast) const SizedBox(height: 20),
                ],
              ),
            ),
          ],
        );
      },
    );
  }
}
